/**********************************************************/
/* Goblin Defense - A tower defense game for Wii Homebrew */
/* Copyright (C) 2009 Ricardo Bueno Cordeiro              */
/* Licensed under de GNU General Public License v2.0      */
/*   See license_gplv2.txt for detalis                    */
/**********************************************************/

#ifndef __MAP_H_
#define __MAP_H_

#include <gccore.h>

#include "trans_array.h"

#include "control_base.h"
#include "path.h"
#include "pony.h"
#include "effect.h"
#include "weapon.h"

#define MAP_SIZE 512

#define MAX_NUM_PONIES 1024
#define MAX_NUM_WEAPONS 1024
#define MAX_NUM_EFFECTS 1024

class Game;

class Map : public ControlBase {
private:
	int loaded_map;

	Game *game;

	PATH *path;

	TransArray<Pony, MAX_NUM_PONIES> ponies;
	TransArray<Weapon, MAX_NUM_WEAPONS> weapons;
	TransArray<Effect, MAX_NUM_EFFECTS> effects;

	TransArray<UpgradableWeapon, MAX_NUM_WEAPONS> upgradable_weapons;
	
	UpgradableWeapon *selected_weapon;

	u32 remain;

	void collision();

public:
	explicit Map(Game *g);

	static int inside(f32 x, f32 y) {
		return (x >= (-MAP_SIZE / 2.0)) && (x < (MAP_SIZE / 2.0)) && (y >= (-MAP_SIZE / 2.0)) && (y < (MAP_SIZE / 2.0));
	}

	int on_path(f32 x, f32 y, f32 r);
	
	void load(int map);
	void unload();

	int add_pony(Pony *p);
	int add_weapon(Weapon *w);
	int add_weapon(UpgradableWeapon *w);
	int add_effect(Effect *e);

	void select_weapon(f32 x, f32 y);
	UpgradableWeapon *get_selected_weapon() { return this->selected_weapon; }
	
	int update(int state, u32 step, WPADData *wiimote_data);
	void draw(int state);
	void text(int state);
};

#endif
